package object;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Menu 
{
	public enum MENU_ITEMS
	{
		LOAD(1, "Load data from directory"),
		TYPE(2, "Create group report by type"),
		HOTEL(3, "Create group report by hotel"),
		WEEK(4, "Create group report by week"),
		DATE(5, "Create report by date"),
		SURNAME(6, "Create report by surname"),
		BOOK(7, "Book tour"),
		CANCEL(8, "Cancel order"),
		SAVE(9, "Save the last report in a text file"),
		EXIT(0, "Exit"),
		UNKNOWN(-1, "");

		private int number;
	    private String description;
	    
	    private MENU_ITEMS(int number, String description) 
	    {
	        this.number = number;
	        this.description = description;
	    }
	    
	    @Override
	    public String toString() 
	    {
	        final StringBuilder stringItem = new StringBuilder();
	        
	        stringItem.append(number).append(". ").append(description);
	        
	        return stringItem.toString();
	    }
	}
	
	
	public void printMenu(boolean isShowSaveItem)
	{
		System.out.println("--------------- MENU ------------------");
		
		for (MENU_ITEMS item: MENU_ITEMS.values()) 
		{
			if (item != MENU_ITEMS.UNKNOWN)
			{
				if (!isShowSaveItem && item == MENU_ITEMS.SAVE)
					continue;
					
				System.out.println(item);
			}
		}
		
		System.out.println("---------------------------------------");
	}
	
	public MENU_ITEMS getMenuItem()
	{
		System.out.print("Choose menu item: ");
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String menuItem = "-1";
		
		try
		{
			menuItem = br.readLine();
		}
		catch (IOException ioe) 
		{
			menuItem = "-1"; 
	    }
		
		int selItem = -1;
		
		try
        {
			selItem = Integer.parseInt(menuItem);
        }
        catch (Exception e)
        {
        	selItem = -1;
        }
		
		MENU_ITEMS result = MENU_ITEMS.UNKNOWN;
		
		switch (selItem) 
		{
			case 1:
				result = MENU_ITEMS.LOAD;
				break;
			case 2:
				result = MENU_ITEMS.TYPE;
				break;
			case 3:
				result = MENU_ITEMS.HOTEL;
				break;
			case 4:
				result = MENU_ITEMS.WEEK;
				break;
			case 5:
				result = MENU_ITEMS.DATE;
				break;
			case 6:
				result = MENU_ITEMS.SURNAME;
				break;
			case 7:
				result = MENU_ITEMS.BOOK;
				break;
			case 8:
				result = MENU_ITEMS.CANCEL;
				break;
			case 9:
				result = MENU_ITEMS.SAVE;
				break;
			case 0:
				result = MENU_ITEMS.EXIT;
				break;
			default:
				result = MENU_ITEMS.UNKNOWN;
				break;
		}
		
		return result;
	}
	
	public void clearConsole()
	{
	    for (int i = 0; i < 50; i++) 
	    {
	    	System.out.println();
		}
	}


}
